package com.sanyue.thread;

/**
 * @author sanyue
 * @version 1.0
 * @description: TODO
 * @date 2022/3/14 上午9:56
 */
public class ThreadABD extends Thread{
    private int num = 0;
    private static final Object LOCK = new Object();

    @Override
    public void run() {
        super.run();
    }
    public void print(String name,int target){
        for (int i = 0; i < 10; i++) {
            synchronized(LOCK){
                while (num % 3 != target){
                    try {
                        LOCK.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                num++;
                System.out.println(Thread.currentThread().getName()+":"+name);
                LOCK.notifyAll();
            }
        }
    }
}
class TestThreadABD{
    public static void main(String[] args) {
        ThreadABD thread = new ThreadABD();
        new Thread(()->{
            thread.print("A",0);
        },"A").start();
        new Thread(()->{
            thread.print("B",1);
        },"B").start();
        new Thread(()->{
            thread.print("D",2);
        },"D").start();
    }
}

